/// @description Insert description here
// You can write your code in this editor
/// @description Insert description here
// You can write your code in this editor
var psp,tmp;

psp=1;// 移动速度

//**AI移动
if(timer>0)timer--;
if(timer==0)
{
	dx=0;
	dy=0;
	switch(irandom(3))
	{
		case 0:{dy=-1;face=1;} break;
		case 1:{dy=1;face=3;} break;
		case 2:{dx=-1;face=2;}break;
		case 3:{dx=1;face=0;}break;
	}
	timer=irandom(64)+16;
}



if(state==0)
{
	
	//**射击
	if(irandom(100)>99)
	{
		tmp=instance_create_depth(x,y,0,obj_bullet_2);
		tmp.speed=2;
		tmp.image_index=face;
		tmp.direction=face*90;
		audio_play_sound(snd_bullet,0,false);
	}
	
}
//***射击CD

//***碰墙检测
if(collision_rectangle(x-7+dx*psp,y-7+dy*psp,x+7+dx*psp,y+7+dy*psp,obj_master,0,0))
{
	timer=0;
	dx=0;
	dy=0;
}
//***移动
x+= dx*psp;
y+= dy*psp;
//***动画控制
if(dx!=0||dy!=0)
{
	image_index+=0.1;
	//audio_play_sound(snd_em_move,0,false);
}


//***方向控制
switch(face)
{
	case 1:sprite_index=spr_em0_up;break;
	case 0:sprite_index=spr_em0_right;break;
	case 3:sprite_index=spr_em0_down;break;
	case 2:sprite_index=spr_em0_left;break;
}